<template>
  <div class="team-wrap">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-fa el-icon-fa fa-group"></i> 旅行团查询
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="container">
      <div class="query-form">
        <el-row :gutter="20">
          <el-col :offset="10" :span="3">
            <el-input
              @keyup.enter.native="query"
              placeholder="团名"
              v-model="queryForm.name"
            />
          </el-col>
          <el-col :span="3">
            <el-input
              @keyup.enter.native="query"
              placeholder="地区名"
              v-model="queryForm.areaName"
            />
          </el-col>
          <el-col :span="3">
            <el-input
              @keyup.enter.native="query"
              placeholder="活动名"
              v-model="queryForm.activityName"
            />
          </el-col>
          <el-col :span="3">
            <el-button @click="query" icon="el-icon-search" type="primary"
              >搜索
            </el-button>
          </el-col>
        </el-row>
      </div>

      <el-row justify="center" type="flex">
        <el-pagination
          :current-page.sync="pageIndex"
          :page-size="pageSize"
          :total="pageSize * pageCount"
          @current-change="getPage"
          background
          layout="prev, pager, next"
        >
        </el-pagination>
      </el-row>

      <div class="table">
        <el-table :data="tableData" stripe>
          <el-table-column label="团Id" prop="id" />
          <el-table-column label="团名" prop="name" />
          <el-table-column label="团最大人数" prop="number" />
          <el-table-column label="所属地区" prop="areaName" />
          <el-table-column label="所属活动" prop="activityName" />
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import * as api from "../../api/member/team";
import * as activityApi from "../../api/member/activity";
export default {
  name: "MemberTeam",
  data() {
    return {
      queryForm: {
        areaName: "",
        activityName: "",
        name: ""
      },
      tableData: [],
      pageSize: api.pageSize,
      pageCount: 1,
      pageIndex: 1,
      editing: false,
      activitys: []
    };
  },
  methods: {
    query() {
      api
        .getPageCount(
          this.queryForm.areaName,
          this.queryForm.activityName,
          this.queryForm.name
        )
        .then(res => {
          this.pageCount = res;
          this.pageIndex = 1;
          this.getPage(1);
        });
    },
    getPage(pageIndex) {
      api
        .getPage(
          pageIndex,
          this.queryForm.areaName,
          this.queryForm.activityName,
          this.queryForm.name
        )
        .then(res => {
          this.tableData = res;
        });
    },
    getActivitys() {
      activityApi.listName().then(res => {
        this.activitys = res;
      });
    }
  },
  created() {
    this.query();
    this.getActivitys();
  }
};
</script>

<style scoped></style>
